<?php
namespace app\member\model;

use app\BaseModel;
use think\facade\Db;

class StoredLevel extends BaseModel
{
    //会员权益表
    protected $name = 'longbing_card_member_level_stored';


    /**
     * @author chenniang
     * @DataTime: 2020-09-07 16:18
     * @功能说明:添加优惠券
     */
    public function addStored($stored, $level_id,$data){

        $this->where(['member_id'=>$level_id])->delete();

        if(!empty($stored)){

            array_walk($stored, function ($value, $key) use (&$stored, $level_id,$data) {

                $stored[$key] = [
                    //等级id
                    'member_id' => $level_id,

                    'uniacid'   => $data['uniacid'],

                    'stored_id' => $value,

                ];

            });
            //添加
            $res = $this->saveAll($stored);
        }

        return true;
    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-11 11:10
     * @功能说明:储值卡类型
     */
    public function storedType($stored_id){

        $dis = [

            'a.stored_id' => $stored_id,

            'b.status'    => 1,

            'b.type'      => 1
        ];

        $data = $this->alias('a')
                ->join('longbing_card_member_level b','a.member_id=b.id')
                ->where($dis)
                ->find();

        return !empty($data)?1:0;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-11 15:49
     * @功能说明:获取puls会员的详情
     */
    public function getLevel($stored_id){

        $dis = [

            'a.stored_id' => $stored_id,

            'b.status'    => 1,

            'b.type'      => 1
        ];

        $data = $this->alias('a')
            ->join('longbing_card_member_level b','a.member_id=b.id')
            ->where($dis)
            ->field('b.*')
            ->find();

        return !empty($data)?$data->toArray():[];

    }





}